package model

import (
	"go_mod_test/utils"
)

// 案例: materiel_classes表中添加数据
func AddMaterielClass(data map[string]interface{}) error {
	cls := &MaterielClasses{MaterielCls: data["materiel_cls"].(string), MterielTyp: data["materiel_type"].(string)}
	if err := utils.DB.Create(cls).Error; err != nil {
		return err
	}

	return nil
}

func GetMaterielClass(data map[string]interface{}) (map[string]interface{}, error) {

	var cls MaterielClasses
	if _, ok := data["materiel_cls"].(string); ok != true {
		panic(utils.NewBadRequst("materiel_cls", 10, map[string]string{
			"materiel_cls": "传递参数中没有该字段"}))
	}
	utils.DB.Where("materiel_cls = ?", data["materiel_cls"].(string)).First(&cls)
	result := utils.StructTomap(cls)
	return result, nil
}



